package com.langll.mcp.portfolio.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.langll.mcp.portfolio.mapper.PortfolioProductMapper;
import com.langll.mcp.portfolio.model.PortfolioProduct;
import com.langll.mcp.portfolio.service.IPortfolioProductService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author langll2
 * @since 2025-03-27
 */
@Service
public class PortfolioProductServiceImpl extends ServiceImpl<PortfolioProductMapper, PortfolioProduct> implements IPortfolioProductService {
    public List<Map<String, Object>> getBusinessSegmentGroup(String businessSegment){
        QueryWrapper<PortfolioProduct> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("PLANNING_CYCLE, BUSINESS_SEGMENT, count(1) as count")
                .eq("main", 1)
                .eq("DELETE_FLAG", 0)
                .eq("LATESTVERSION", 1)
                .le("PLANNING_CYCLE","FY 25/26")
                .groupBy("PLANNING_CYCLE", "BUSINESS_SEGMENT")
                .orderByAsc("PLANNING_CYCLE");
        if(StrUtil.isNotBlank(businessSegment)){
            queryWrapper.eq("BUSINESS_SEGMENT", businessSegment);
        }
        return this.getBaseMapper().selectMaps(queryWrapper);
    }

}
